import Vue from 'vue'
import Router from 'vue-router'

const header = r => require.ensure([], () => r(require('@/components/header/header.vue')), 'index')
// login
const login = r => require.ensure([], () => r(require('@/components/login/login.vue')), 'index')
// 404
const notFound = r => require.ensure([], () => r(require('@/components/index/404.vue')), 'index')
// nav-首页
const index = r => require.ensure([], () => r(require('@/components/index/index.vue')), 'index')
// 产品列表
const product = r => require.ensure([], () => r(require('@/components/product/product.vue')), 'index')
// 产品中心新增
const productAdd = r => require.ensure([], () => r(require('@/components/product/productAdd.vue')), 'product')
// 详情dails
const dails = r => require.ensure([], () => r(require('@/components/dails/dails.vue')), 'index')
Vue.use(Router)

const router = new Router({
  // mode: 'history',
  scrollBehavior (to, from, savedPosition) {
    return {x: 0, y: 0}
  },
  routes: [
    {
      path: '/login',
      name: 'login',
      component: login,
      hidden: true
    },
    {
      path: '/',
      name: '',
      component: header,
      iconCls: 'iconfont icon-index', // 图标样式class
      leaf: true, // 只有一个节点
      children: [
        {path: '/index', component: index, name: '首页'}
        // {path: '/product', component: product, name: '产品'},
        // {path: '/dails', component: dails, name: '详情'}
      ]
    },
    {
      path: '/',
      name: '',
      component: header,
      iconCls: 'iconfont icon-chanpin', // 图标样式class
      leaf: true, // 只有一个节点
      children: [
        {path: '/product', component: product, name: '产品'},
        {path: '/productAdd', component: productAdd, name: '产品新增'}
      ]
    },
    {
      path: '/',
      name: '',
      component: header,
      iconCls: 'iconfont icon-xiangqing', // 图标样式class
      leaf: true, // 只有一个节点
      children: [
        {path: '/dails', component: dails, name: '详情'}
      ]
    },
    {
      path: '*',
      name: '404',
      component: notFound,
      hidden: true
    }
  ]
})

router.beforeEach((to, from, next) => {
  // console.log('from:', from.fullPath, ',to: ', to.fullPath)
  next()
})

export default router
